/////////////////////////////////////////////////////////////////////////////
// Name:        windowfilters.cpp
// Purpose:     
// Author:      Stephen Whittle
// Modified by: 
// Created:     24/06/2009 03:05:32
// RCS-ID:      
// Copyright:   
// Licence:     
/////////////////////////////////////////////////////////////////////////////

// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
#pragma hdrstop
#endif

#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif

////@begin includes
#include "wx/imaglist.h"
////@end includes

#include "windowfilters.h"
#include "globals.h"

////@begin XPM images
////@end XPM images


/*
 * WindowFilters type definition
 */

IMPLEMENT_CLASS( WindowFilters, wxFrame )


/*
 * WindowFilters event table definition
 */

BEGIN_EVENT_TABLE( WindowFilters, wxFrame )

////@begin WindowFilters event table entries
    EVT_LISTBOX( ID_LISTBOX, WindowFilters::OnListboxSelected )

    EVT_LISTBOX( ID_LISTBOX1, WindowFilters::OnFilterListSelected )

    EVT_BUTTON( ID_BUTTON4, WindowFilters::OnAddFilterClick )

    EVT_BUTTON( ID_BUTTON5, WindowFilters::OnRemoveClick )

    EVT_BUTTON( ID_BUTTON1, WindowFilters::OnCloseClick )

////@end WindowFilters event table entries

END_EVENT_TABLE()


/*
 * WindowFilters constructors
 */

WindowFilters::WindowFilters()
{
    Init();
}

WindowFilters::WindowFilters( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
{
    Init();
    Create( parent, id, caption, pos, size, style );
}


/*
 * WindowFilters creator
 */

bool WindowFilters::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
{
////@begin WindowFilters creation
    wxFrame::Create( parent, id, caption, pos, size, style );

    CreateControls();
    Centre();
////@end WindowFilters creation
    return true;
}


/*
 * WindowFilters destructor
 */

WindowFilters::~WindowFilters()
{
////@begin WindowFilters destruction
////@end WindowFilters destruction
}


/*
 * Member initialisation
 */

void WindowFilters::Init()
{
////@begin WindowFilters member initialisation
    m_WindowList = NULL;
    m_FilterList = NULL;
    m_FilterString = NULL;
////@end WindowFilters member initialisation
}


/*
 * Control creation for WindowFilters
 */

void WindowFilters::CreateControls()
{    
////@begin WindowFilters content construction
    WindowFilters* itemFrame1 = this;

    wxPanel* itemPanel2 = new wxPanel( itemFrame1, ID_PANEL2, wxDefaultPosition, wxSize(450, -1), wxSUNKEN_BORDER|wxTAB_TRAVERSAL );

    wxFlexGridSizer* itemFlexGridSizer3 = new wxFlexGridSizer(0, 2, 0, 0);
    itemFlexGridSizer3->AddGrowableRow(0);
    itemFlexGridSizer3->AddGrowableCol(1);
    itemPanel2->SetSizer(itemFlexGridSizer3);

    wxArrayString m_WindowListStrings;
    m_WindowList = new wxListBox( itemPanel2, ID_LISTBOX, wxDefaultPosition, wxDefaultSize, m_WindowListStrings, wxLB_SINGLE );
    itemFlexGridSizer3->Add(m_WindowList, 0, wxALIGN_LEFT|wxGROW|wxALL, 5);

    wxNotebook* itemNotebook5 = new wxNotebook( itemPanel2, ID_NOTEBOOK, wxDefaultPosition, wxDefaultSize, wxBK_DEFAULT );

    wxPanel* itemPanel6 = new wxPanel( itemNotebook5, ID_PANEL1, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER|wxTAB_TRAVERSAL );
    wxFlexGridSizer* itemFlexGridSizer7 = new wxFlexGridSizer(0, 2, 0, 0);
    itemFlexGridSizer7->AddGrowableRow(0);
    itemFlexGridSizer7->AddGrowableCol(0);
    itemPanel6->SetSizer(itemFlexGridSizer7);

    wxArrayString m_FilterListStrings;
    m_FilterList = new wxListBox( itemPanel6, ID_LISTBOX1, wxDefaultPosition, wxDefaultSize, m_FilterListStrings, wxLB_SINGLE );
    itemFlexGridSizer7->Add(m_FilterList, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);

    itemFlexGridSizer7->Add(5, 5, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);

    m_FilterString = new wxTextCtrl( itemPanel6, ID_TEXTCTRL2, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
    itemFlexGridSizer7->Add(m_FilterString, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxButton* itemButton11 = new wxButton( itemPanel6, ID_BUTTON4, _("Add"), wxDefaultPosition, wxDefaultSize, 0 );
    itemFlexGridSizer7->Add(itemButton11, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);

    itemFlexGridSizer7->Add(5, 5, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxButton* itemButton13 = new wxButton( itemPanel6, ID_BUTTON5, _("Remove"), wxDefaultPosition, wxDefaultSize, 0 );
    itemFlexGridSizer7->Add(itemButton13, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);

    itemNotebook5->AddPage(itemPanel6, _("Filters"));

    wxPanel* itemPanel14 = new wxPanel( itemNotebook5, ID_PANEL3, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER|wxTAB_TRAVERSAL );
    wxStaticText* itemStaticText15 = new wxStaticText( itemPanel14, wxID_STATIC, _("To be Implemented"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE );

    itemNotebook5->AddPage(itemPanel14, _("Highlights"));

    wxPanel* itemPanel16 = new wxPanel( itemNotebook5, ID_PANEL4, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER|wxTAB_TRAVERSAL );
    wxStaticText* itemStaticText17 = new wxStaticText( itemPanel16, wxID_STATIC, _("To be Implemented"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE );

    itemNotebook5->AddPage(itemPanel16, _("Substitutions"));

    wxPanel* itemPanel18 = new wxPanel( itemNotebook5, ID_PANEL5, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER|wxTAB_TRAVERSAL );
    wxStaticText* itemStaticText19 = new wxStaticText( itemPanel18, wxID_STATIC, _("To be Implemented"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE );

    itemNotebook5->AddPage(itemPanel18, _("Misc"));

    itemFlexGridSizer3->Add(itemNotebook5, 0, wxGROW|wxGROW|wxALL, 5);

    itemFlexGridSizer3->Add(5, 5, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxFlexGridSizer* itemFlexGridSizer21 = new wxFlexGridSizer(0, 3, 0, 0);
    itemFlexGridSizer3->Add(itemFlexGridSizer21, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxButton* itemButton22 = new wxButton( itemPanel2, ID_BUTTON1, _("OK"), wxDefaultPosition, wxDefaultSize, 0 );
    itemFlexGridSizer21->Add(itemButton22, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);

////@end WindowFilters content construction

//loop through and call this with a pointer to each window and get its name
    int i = 0;
    wxString * label;
    while (i < mudTextWindows.GetCount()){
        label = &((mudTextWindows[i])->windowName);
        m_WindowList->InsertItems(1,label , i);
        //itemListBox4->InsertItems(mudTextWindows[i]->GetName());
        i++;
    }
   selectedWindow = NULL;
}


/*
 * Should we show tooltips?
 */

bool WindowFilters::ShowToolTips()
{
    return true;
}

/*
 * Get bitmap resources
 */

wxBitmap WindowFilters::GetBitmapResource( const wxString& name )
{
    // Bitmap retrieval
////@begin WindowFilters bitmap retrieval
    wxUnusedVar(name);
    return wxNullBitmap;
////@end WindowFilters bitmap retrieval
}

/*
 * Get icon resources
 */

wxIcon WindowFilters::GetIconResource( const wxString& name )
{
    // Icon retrieval
////@begin WindowFilters icon retrieval
    wxUnusedVar(name);
    return wxNullIcon;
////@end WindowFilters icon retrieval
}


/*
 * wxEVT_COMMAND_LISTBOX_SELECTED event handler for ID_LISTBOX
 */

void WindowFilters::OnListboxSelected( wxCommandEvent& event )
{
selectedWindow = mudTextWindows[(m_WindowList->GetSelection())];
//get index using mudTextWindows.Index(getSelection)
//mudTextWindows[mudTextWindows.Index(getSelection)]->filterList.GetCount
m_FilterList->Clear();
    int i = 0;
    wxString * label;
    while (i < (selectedWindow->filterList.GetCount())){
        label = &(selectedWindow->filterList[i]);
        m_FilterList->InsertItems(1,label , 0);
        i++;
    }

}


/*
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON4
 */

void WindowFilters::OnAddFilterClick( wxCommandEvent& event )
{
if (!selectedWindow){
    return;
}
//eventually use accessor function
    (selectedWindow->filterList).Add( m_FilterString->GetValue());
    m_FilterList->Clear();
    int i = 0;
    wxString * label;
    while (i < (selectedWindow->filterList.GetCount())){
        label = &(selectedWindow->filterList[i]);
        m_FilterList->InsertItems(1,label , 0);
        i++;
    }
    m_FilterString->Clear();
}


/*
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON5
 */

void WindowFilters::OnRemoveClick( wxCommandEvent& event )
{
if (!selectedWindow){
    return;
}
(selectedWindow->filterList).Remove( m_FilterString->GetValue());
    m_FilterList->Clear();
    int i = 0;
    wxString * label;
    while (i < (selectedWindow->filterList.GetCount())){
        label = &(selectedWindow->filterList[i]);
        m_FilterList->InsertItems(1,label , 0);
        i++;
    }
    m_FilterString->Clear();
}


/*
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON1
 */

void WindowFilters::OnCloseClick( wxCommandEvent& event )
{
////@begin wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON1 in WindowFilters.
    // Before editing this code, remove the block markers.
    Destroy();
////@end wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON1 in WindowFilters. 
}


/*
 * wxEVT_COMMAND_LISTBOX_SELECTED event handler for ID_LISTBOX1
 */

void WindowFilters::OnFilterListSelected( wxCommandEvent& event )
{
    m_FilterString->ChangeValue(m_FilterList->GetStringSelection());
}

